
import * as actions from './';
//   import BSPError from './../common/bsperror';
import HttpRequest from './../common/http';
  
const rootUrl = window.restConfig.rootUrl;

export const accommodationInit = () => {
  return (dispatch, getState) => {
    dispatch({
    type: actions.ACCOMMODATION_INIT
    })
  }
}
  
export const getAccommodation = (id) => {
  return (dispatch) => {
    HttpRequest.get(rootUrl + '/accommodation/'+id)
      .then((ret) => {
        let arr = [ret.data];
        dispatch({
          type: actions.ACCOMMODATION_CHANGE,
          data: {
            state: arr
          }
        })
      }).catch((err) => {
        dispatch({
          type: actions.ACCOMMODATION_CHANGE,
          data: err.message
        })
      });
  }
}

export const stateChange = (newState) => {
  return {
    type: actions.ACCOMMODATION_CHANGE,
    data: {
      state: newState
    }
  }
}